using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bEmployee
    {
        public static int insertEmployee(eEmployee employee)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@employeeUserName", SqlDbType.VarChar);
            pr.Value = employee.employeeUserName;
            paramList.Add(pr);

            pr = new SqlParameter("@employeePassword", SqlDbType.VarChar);
            pr.Value = employee.employeePassword;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeFullName", SqlDbType.NVarChar);
            pr.Value = employee.employeeFullName;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeAddress", SqlDbType.NVarChar);
            pr.Value = employee.employeeAddress;
            paramList.Add(pr);

            pr = new SqlParameter("@employeePhone", SqlDbType.VarChar);
            pr.Value = employee.employeePhone;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeEmail", SqlDbType.NVarChar);
            pr.Value = employee.employeeEmail;
            paramList.Add(pr);

            pr = new SqlParameter("@typeID", SqlDbType.NVarChar);
            pr.Value = employee.typeID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("insertEmployee", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int updateEmployee(eEmployee employee)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();

            SqlParameter pr = new SqlParameter("@employeeID", SqlDbType.Int);
            pr.Value = employee.employeeID;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeUserName", SqlDbType.VarChar);
            pr.Value = employee.employeeUserName;
            paramList.Add(pr);

            pr = new SqlParameter("@employeePassword", SqlDbType.VarChar);
            pr.Value = employee.employeePassword;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeFullName", SqlDbType.NVarChar);
            pr.Value = employee.employeeFullName;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeAddress", SqlDbType.NVarChar);
            pr.Value = employee.employeeAddress;
            paramList.Add(pr);

            pr = new SqlParameter("@employeePhone", SqlDbType.VarChar);
            pr.Value = employee.employeePhone;
            paramList.Add(pr);

            pr = new SqlParameter("@employeeEmail", SqlDbType.NVarChar);
            pr.Value = employee.employeeEmail;
            paramList.Add(pr);

            pr = new SqlParameter("@typeID", SqlDbType.NVarChar);
            pr.Value = employee.typeID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("updateEmployee", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int deleteEmployee(int employeeID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@employeeID", SqlDbType.Int);
            pr.Value = employeeID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deleteEmployee", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static DataTable getAllEmployee()
        {
            DBHelper dbh = new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllEmployee", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        // neu username va pass dung thi tra ve doi tuong eEmployee ,neu sai tra ve null
        public static eEmployee employeeLogin(String UserName, String Password)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@employeeUserName", SqlDbType.VarChar);
            pr.Value = UserName;
            paramList.Add(pr);

            pr = new SqlParameter("@employeePassword", SqlDbType.VarChar);
            pr.Value = Password;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(eEmployee), "employeeLogin", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eEmployee)il[0];
            }
            else
            {
                return null;
            }
        }

        public static eEmployee getEmployeeByID(int employeeID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@employeeID", SqlDbType.Int);
            pr.Value = employeeID;
            paramList.Add(pr);


            IList il = bBase.LoadQueryString(typeof(eEmployee), "getEmployeeByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eEmployee)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
